/********************************
 *版权所有 CopyRight(c) 快程乐码信息有限公司所有，未经授权，不得复制、转发
 */
package com.yjx.test.dozer;

import com.yjx.test.dozer.dto.NameDto;
import com.yjx.test.dozer.entity.*;
import com.yjx.test.dozer.utils.DataConvertor;
import org.dozer.Mapper;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.time.LocalDate;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/************
 *@Author yejx
 *@version v1.0
 *@create 2020/7/1 10:26
 *@Description TODO
 *
 */
@SpringBootTest
public class DozerApplicationTest3 {

    @Autowired
    DataConvertor dataConvertor;

    @Test
    public void Test() {
        LocalDateA localDateA = new LocalDateA();
        localDateA.setLocalDate1(LocalDate.now());
        LocalDateB localDateB = new LocalDateB();
        dataConvertor.convertor(localDateA, localDateB);
        System.out.println(localDateB);
    }

    @Test
    public void Test1() {
        Cat cat = new Cat();
        cat.setEatFish("鱼真香");
        Dog dog = new Dog();
        dog.setEatMeat("肉更香");
        Animal animal = new Animal();
        dataConvertor.convertor(cat, animal);
        dataConvertor.convertor(dog, animal);
        System.out.println(animal);
    }

    @Test
    public void test2() throws InstantiationException, IllegalAccessException {
        List<Cat> cats = Arrays.asList(new Cat("黑猫", "鱼真香1"), new Cat("白猫", "鱼真香2"), new Cat("狸花猫", "鱼真香3"));
        List<Dog> dogs = Arrays.asList(new Dog("狗肉更香1"), new Dog("狗肉更香2"), new Dog("狗肉更香3"));
        List<Animal> convertor = dataConvertor.convertor(cats, dogs, Animal.class);
        convertor.forEach(System.out::println);
    }


    @Test
    public void test3() {
        Map<Integer, Name> sourceMap = new HashMap<>();
        sourceMap.put(1, new Name("叶", "建雄", "叶建雄"));
        sourceMap.put(2, new Name("谭", "建", "谭建"));
        sourceMap.put(3, new Name("张", "一封", "张一封"));
        Map<Integer, NameDto> convertor = dataConvertor.convertor(sourceMap, NameDto.class);
        convertor.forEach((x, y) -> {
            System.out.println(x + "------------------>" + y);
        });

    }

}
